Box::new(self.packages.iter().map(|&(ref p, _)| p))
}
- pub fn get(&self, id: &PackageId, config: &Config) -> CargoResult<&Package> {
+ pub fn get(&self, id: &PackageId) -> CargoResult<&Package> {
let slot = try!(self.packages.iter().find(|p| p.0 == *id).chain_error(|| {
internal(format!("couldn't find `{}` in package set", id))
}));
let source = try!(sources.get_mut(id.source_id()).chain_error(|| {
internal(format!("couldn't find source for `{}`", id))
}));
- let pkg = try!(source.download(id, config).chain_error(|| {
+ let pkg = try!(source.download(id).chain_error(|| {
human("unable to get packages from source")
}));
assert!(slot.fill(pkg).is_ok());
/// See also `core::Source`.
pub trait Registry {
/// Attempt to find the packages that match a dependency request.
- fn query(&mut self, name: &Dependency, config: &Config) -> CargoResult<Vec<Summary>>;
+ fn query(&mut self, name: &Dependency) -> CargoResult<Vec<Summary>>;
/// Returns whether or not this registry will return summaries with
/// checksums listed.
}
impl Registry for Vec<Summary> {
- fn query(&mut self, dep: &Dependency, _config: &Config) -> CargoResult<Vec<Summary>> {
+ fn query(&mut self, dep: &Dependency) -> CargoResult<Vec<Summary>> {
Ok(self.iter().filter(|summary| dep.matches(*summary))
.cloned().collect())
}
}
impl Registry for Vec<Package> {
- fn query(&mut self, dep: &Dependency, _config: &Config) -> CargoResult<Vec<Summary>> {
+ fn query(&mut self, dep: &Dependency) -> CargoResult<Vec<Summary>> {
Ok(self.iter().filter(|pkg| dep.matches(pkg.summary()))
.map(|pkg| pkg.summary().clone()).collect())
}
}
impl<'a, T: ?Sized + Registry + 'a> Registry for Box<T> {
- fn query(&mut self, name: &Dependency, config: &Config) -> CargoResult<Vec<Summary>> {
- (**self).query(name, config)
+ fn query(&mut self, name: &Dependency) -> CargoResult<Vec<Summary>> {
+ (**self).query(name)
}
}
use core::{PackageId, Registry, SourceId, Summary, Dependency};
use core::PackageIdSpec;
-use util::{CargoResult, Graph, human, CargoError, Config};
+use util::{CargoResult, Graph, human, CargoError};
use util::profile;
use util::ChainError;
use util::graph::{Nodes, Edges};
/// Builds the list of all packages required to build the first argument.
pub fn resolve(summaries: &[(Summary, Method)],
replacements: &[(PackageIdSpec, Dependency)],
- registry: &mut Registry,
- config: &Config) -> CargoResult<Resolve> {
+ registry: &mut Registry) -> CargoResult<Resolve> {
let cx = Context {
resolve_graph: Graph::new(),
resolve_features: HashMap::new(),
replacements: replacements,
};
let _p = profile::start(format!("resolving"));
- let cx = try!(activate_deps_loop(cx, registry, summaries, config));
+ let cx = try!(activate_deps_loop(cx, registry, summaries));
let mut resolve = Resolve {
graph: cx.resolve_graph,
registry: &mut Registry,
parent: Option<&Rc<Summary>>,
candidate: Candidate,
- method: &Method,
- config: &Config)
+ method: &Method)
-> CargoResult<Option<DepsFrame>> {
if let Some(parent) = parent {
cx.resolve_graph.link(parent.package_id().clone(),
}
};
- let deps = try!(cx.build_deps(registry, &candidate, method, config));
+ let deps = try!(cx.build_deps(registry, &candidate, method));
Ok(Some(DepsFrame {
parent: candidate,
/// dependency graph, cx.resolve is returned.
fn activate_deps_loop<'a>(mut cx: Context<'a>,
registry: &mut Registry,
- summaries: &[(Summary, Method)],
- config: &Config)
+ summaries: &[(Summary, Method)])
-> CargoResult<Context<'a>> {
// Note that a `BinaryHeap` is used for the remaining dependencies that need
// activation. This heap is sorted such that the "largest value" is the most
let summary = Rc::new(summary.clone());
let candidate = Candidate { summary: summary, replace: None };
remaining_deps.extend(try!(activate(&mut cx, registry, None, candidate,
- method, config)));
+ method)));
}
// Main resolution loop, this is the workhorse of the resolution algorithm.
None => return Err(activation_error(&cx, registry, &parent,
&dep,
&cx.prev_active(&dep),
- &candidates,
- config)),
+ &candidates)),
Some(candidate) => candidate,
}
}
trace!("{}[{}]>{} trying {}", parent.name(), cur, dep.name(),
candidate.summary.version());
remaining_deps.extend(try!(activate(&mut cx, registry, Some(&parent),
- candidate, &method, config)));
+ candidate, &method)));
}
Ok(cx)
parent: &Summary,
dep: &Dependency,
prev_active: &[Rc<Summary>],
- candidates: &[Candidate],
- config: &Config) -> Box<CargoError> {
+ candidates: &[Candidate]) -> Box<CargoError> {
if candidates.len() > 0 {
let mut msg = format!("failed to select a version for `{}` \
(required by `{}`):\n\
let mut msg = msg;
let all_req = semver::VersionReq::parse("*").unwrap();
let new_dep = dep.clone_inner().set_version_req(all_req).into_dependency();
- let mut candidates = match registry.query(&new_dep, config) {
+ let mut candidates = match registry.query(&new_dep) {
Ok(candidates) => candidates,
Err(e) => return e,
};
fn build_deps(&mut self,
registry: &mut Registry,
candidate: &Summary,
- method: &Method,
- config: &Config) -> CargoResult<Vec<DepInfo>> {
+ method: &Method) -> CargoResult<Vec<DepInfo>> {
// First, figure out our set of dependencies based on the requsted set
// of features. This also calculates what features we're going to enable
// for our own dependencies.
// Next, transform all dependencies into a list of possible candidates
// which can satisfy that dependency.
let mut deps = try!(deps.into_iter().map(|(dep, features)| {
- let mut candidates = try!(self.query(registry, &dep, config));
+ let mut candidates = try!(self.query(registry, &dep));
// When we attempt versions for a package, we'll want to start at
// the maximum version and work our way down.
candidates.sort_by(|a, b| {
/// return.
fn query(&self,
registry: &mut Registry,
- dep: &Dependency,
- config: &Config) -> CargoResult<Vec<Candidate>> {
- let summaries = try!(registry.query(dep, config));
+ dep: &Dependency) -> CargoResult<Vec<Candidate>> {
+ let summaries = try!(registry.query(dep));
summaries.into_iter().map(Rc::new).map(|summary| {
// get around lack of non-lexical lifetimes
let summary2 = summary.clone();
Some(replacement) => replacement,
};
- let mut summaries = try!(registry.query(dep, config)).into_iter();
+ let mut summaries = try!(registry.query(dep)).into_iter();
let s = try!(summaries.next().chain_error(|| {
human(format!("no matching package for override `{}` found\n\
location searched: {}\n\
/// The download method fetches the full package for each name and
/// version specified.
- fn download(&mut self, package: &PackageId, config: &Config) -> CargoResult<Package>;
+ fn download(&mut self, package: &PackageId) -> CargoResult<Package>;
/// Generates a unique string which represents the fingerprint of the
/// current state of the source.
(**self).update()
}
- fn download(&mut self, id: &PackageId, config: &Config) -> CargoResult<Package> {
- (**self).download(id, config)
+ fn download(&mut self, id: &PackageId) -> CargoResult<Package> {
+ (**self).download(id)
}
fn fingerprint(&self, pkg: &Package) -> CargoResult<String> {
for spec in opts.spec {
// Translate the spec to a Package
let pkgid = try!(resolve.query(spec));
- let pkg = try!(packages.get(&pkgid, ws.config()));
+ let pkg = try!(packages.get(&pkgid));
// Generate all relevant `Unit` targets for this package
for target in pkg.targets() {
};
let to_builds = try!(pkgids.iter().map(|id| {
- packages.get(id, config)
+ packages.get(id)
}).collect::<CargoResult<Vec<_>>>());
let mut general_targets = Vec::new();
let resolve = try!(ops::resolve_ws(&mut registry, ws));
let packages = get_resolved_packages(&resolve, registry);
for id in resolve.iter() {
- try!(packages.get(id, ws.config()));
+ try!(packages.get(id));
}
Ok((resolve, packages))
}
match name {
Some(name) => {
let dep = try!(Dependency::parse(name, vers, source_id, config));
- let deps = try!(source.query(&dep, config));
+ let deps = try!(source.query(&dep));
match deps.iter().map(|p| p.package_id()).max() {
Some(pkgid) => {
- let pkg = try!(source.download(pkgid, config));
+ let pkg = try!(source.download(pkgid));
Ok((pkg, Box::new(source)))
}
None => {
let (packages, resolve) = deps;
let packages = try!(packages.package_ids()
- .map(|i| packages.get(i, ws.config()).map(|p| p.clone()))
+ .map(|i| packages.get(i).map(|p| p.clone()))
.collect());
Ok(ExportInfo {
}
}));
}
- for dep in try!(self.dep_targets(&unit, self.config)) {
+ for dep in try!(self.dep_targets(&unit)) {
try!(self.visit_crate_type(&dep, crate_types));
}
Ok(())
for unit in units {
try!(self.walk_used_in_plugin_map(unit,
unit.target.for_host(),
- &mut visited,
- self.config));
+ &mut visited));
}
Ok(())
}
fn walk_used_in_plugin_map(&mut self,
unit: &Unit<'a>,
is_plugin: bool,
- visited: &mut HashSet<(Unit<'a>, bool)>,
- config: &Config)
+ visited: &mut HashSet<(Unit<'a>, bool)>)
-> CargoResult<()> {
if !visited.insert((*unit, is_plugin)) {
return Ok(())
if is_plugin {
self.used_in_plugin.insert(*unit);
}
- for unit in try!(self.dep_targets(unit, config)) {
+ for unit in try!(self.dep_targets(unit)) {
try!(self.walk_used_in_plugin_map(&unit,
is_plugin || unit.target.for_host(),
- visited,
- config));
+ visited));
}
Ok(())
}
/// For a package, return all targets which are registered as dependencies
/// for that package.
- pub fn dep_targets(&self, unit: &Unit<'a>, config: &Config) -> CargoResult<Vec<Unit<'a>>> {
+ pub fn dep_targets(&self, unit: &Unit<'a>) -> CargoResult<Vec<Unit<'a>>> {
if unit.profile.run_custom_build {
return self.dep_run_custom_build(unit)
} else if unit.profile.doc {
- return self.doc_deps(unit, config);
+ return self.doc_deps(unit);
}
let id = unit.pkg.package_id();
true
})
}).filter_map(|id| {
- match self.get_package(id, config) {
+ match self.get_package(id) {
Ok(pkg) => {
pkg.targets().iter().find(|t| t.is_lib()).map(|t| {
Ok(Unit {
profile: &self.profiles.dev,
..*unit
};
- let deps = try!(self.dep_targets(&tmp, self.config));
+ let deps = try!(self.dep_targets(&tmp));
Ok(deps.iter().filter_map(|unit| {
if !unit.target.linkable() || unit.pkg.manifest().links().is_none() {
return None
}
/// Returns the dependencies necessary to document a package
- fn doc_deps(&self, unit: &Unit<'a>, config: &Config) -> CargoResult<Vec<Unit<'a>>> {
+ fn doc_deps(&self, unit: &Unit<'a>) -> CargoResult<Vec<Unit<'a>>> {
let deps = self.resolve.deps(unit.pkg.package_id()).filter(|dep| {
unit.pkg.dependencies().iter().filter(|d| {
d.name() == dep.name()
}
})
}).map(|dep| {
- self.get_package(dep, config)
+ self.get_package(dep)
});
// To document a library, we depend on dependencies actually being
}
/// Gets a package for the given package id.
- pub fn get_package(&self, id: &PackageId, config: &Config) -> CargoResult<&'a Package> {
- self.packages.get(id, config)
+ pub fn get_package(&self, id: &PackageId) -> CargoResult<&'a Package> {
+ self.packages.get(id)
}
/// Get the user-specified linker for a particular host or target
if !unit.target.is_custom_build() && unit.pkg.has_custom_build() {
add_to_link(&mut ret, unit.pkg.package_id(), unit.kind);
}
- for unit in try!(cx.dep_targets(unit, cx.config)).iter() {
+ for unit in try!(cx.dep_targets(unit)).iter() {
let dep_scripts = try!(build(out, cx, unit));
if unit.target.for_host() {
// elsewhere. Also skip fingerprints of binaries because they don't actually
// induce a recompile, they're just dependencies in the sense that they need
// to be built.
- let deps = try!(cx.dep_targets(unit, cx.config));
+ let deps = try!(cx.dep_targets(unit));
let deps = try!(deps.iter().filter(|u| {
!u.target.is_custom_build() && !u.target.is_bin()
}).map(|unit| {
fn dependencies<'cfg>(&self, cx: &Context<'a, 'cfg>)
-> CargoResult<Vec<Key<'a>>> {
let unit = Unit {
- pkg: try!(cx.get_package(self.pkg, cx.config)),
+ pkg: try!(cx.get_package(self.pkg)),
target: self.target,
profile: self.profile,
kind: self.kind,
};
- let targets = try!(cx.dep_targets(&unit, cx.config));
+ let targets = try!(cx.dep_targets(&unit));
Ok(targets.iter().filter_map(|unit| {
// Binaries aren't actually needed to *compile* tests, just to run
// them, so we don't include this dependency edge in the job graph.
if !unit.target.is_lib() { continue }
// Include immediate lib deps as well
- for unit in try!(cx.dep_targets(unit, cx.config)).iter() {
+ for unit in try!(cx.dep_targets(unit)).iter() {
let pkgid = unit.pkg.package_id();
if !unit.target.is_lib() { continue }
if unit.profile.doc { continue }
drop(p);
// Be sure to compile all dependencies of this target as well.
- for unit in try!(cx.dep_targets(unit, cx.config)).iter() {
+ for unit in try!(cx.dep_targets(unit)).iter() {
try!(compile(cx, jobs, unit));
}
Ok(())
cmd.env("OUT_DIR", &layout.build_out(unit.pkg));
}
- for unit in try!(cx.dep_targets(unit, cx.config)).iter() {
+ for unit in try!(cx.dep_targets(unit)).iter() {
if unit.target.linkable() && !unit.profile.doc {
try!(link_to(cmd, cx, unit));
}
None => root_replace.to_vec(),
};
- let mut resolved = try!(resolver::resolve(&summaries, &replace, registry, ws.config()));
+ let mut resolved = try!(resolver::resolve(&summaries, &replace, registry));
if let Some(previous) = previous {
try!(resolved.merge_from(previous));
}
}
impl<'cfg> Registry for DirectorySource<'cfg> {
- fn query(&mut self, dep: &Dependency, _config: &Config) -> CargoResult<Vec<Summary>> {
+ fn query(&mut self, dep: &Dependency) -> CargoResult<Vec<Summary>> {
let packages = self.packages.values().map(|p| &p.0);
let matches = packages.filter(|pkg| dep.matches(pkg.summary()));
let summaries = matches.map(|pkg| pkg.summary().clone());
Ok(())
}
- fn download(&mut self, id: &PackageId, _config: &Config) -> CargoResult<Package> {
+ fn download(&mut self, id: &PackageId) -> CargoResult<Package> {
self.packages.get(id).map(|p| &p.0).cloned().chain_error(|| {
human(format!("failed to find package with id: {}", id))
})
}
impl<'cfg> Registry for GitSource<'cfg> {
- fn query(&mut self, dep: &Dependency, config: &Config) -> CargoResult<Vec<Summary>> {
+ fn query(&mut self, dep: &Dependency) -> CargoResult<Vec<Summary>> {
let src = self.path_source.as_mut()
.expect("BUG: update() must be called before query()");
- src.query(dep, config)
+ src.query(dep)
}
}
self.path_source.as_mut().unwrap().update()
}
- fn download(&mut self, id: &PackageId, config: &Config) -> CargoResult<Package> {
+ fn download(&mut self, id: &PackageId) -> CargoResult<Package> {
trace!("getting packages for package id `{}` from `{:?}`", id,
self.remote);
self.path_source.as_mut()
.expect("BUG: update() must be called before get()")
- .download(id, config)
+ .download(id)
}
fn fingerprint(&self, _pkg: &Package) -> CargoResult<String> {
}
impl<'cfg> Registry for PathSource<'cfg> {
- fn query(&mut self, dep: &Dependency, config: &Config) -> CargoResult<Vec<Summary>> {
- self.packages.query(dep, config)
+ fn query(&mut self, dep: &Dependency) -> CargoResult<Vec<Summary>> {
+ self.packages.query(dep)
}
}
Ok(())
}
- fn download(&mut self, id: &PackageId, _config: &Config) -> CargoResult<Package> {
+ fn download(&mut self, id: &PackageId) -> CargoResult<Package> {
trace!("getting packages; id={}", id);
let pkg = self.packages.iter().find(|pkg| pkg.package_id() == id);
}
/// Return the hash listed for a specified PackageId.
- pub fn hash(&mut self, pkg: &PackageId, config: &Config) -> CargoResult<String> {
+ pub fn hash(&mut self, pkg: &PackageId) -> CargoResult<String> {
let key = (pkg.name().to_string(), pkg.version().to_string());
if let Some(s) = self.hashes.get(&key) {
return Ok(s.clone())
}
// Ok, we're missing the key, so parse the index file to load it.
- try!(self.summaries(pkg.name(), config));
+ try!(self.summaries(pkg.name()));
self.hashes.get(&key).chain_error(|| {
internal(format!("no hash listed for {}", pkg))
}).map(|s| s.clone())
///
/// Returns a list of pairs of (summary, yanked) for the package name
/// specified.
- pub fn summaries(&mut self, name: &str, config: &Config) -> CargoResult<&Vec<(Summary, bool)>> {
+ pub fn summaries(&mut self, name: &str) -> CargoResult<&Vec<(Summary, bool)>> {
if self.cache.contains_key(name) {
return Ok(self.cache.get(name).unwrap());
}
- let summaries = try!(self.load_summaries(name, config));
+ let summaries = try!(self.load_summaries(name));
let summaries = summaries.into_iter().filter(|summary| {
summary.0.package_id().name() == name
}).collect();
Ok(self.cache.get(name).unwrap())
}
- fn load_summaries(&mut self, name: &str, config: &Config) -> CargoResult<Vec<(Summary, bool)>> {
+ fn load_summaries(&mut self, name: &str) -> CargoResult<Vec<(Summary, bool)>> {
let (path, _lock) = if self.locked {
let lock = self.path.open_ro(Path::new(INDEX_LOCK),
self.config,
try!(f.read_to_string(&mut contents));
let ret: CargoResult<Vec<(Summary, bool)>>;
ret = contents.lines().filter(|l| l.trim().len() > 0)
- .map(|l| self.parse_registry_package(l, config))
+ .map(|l| self.parse_registry_package(l))
.collect();
ret.chain_error(|| {
internal(format!("failed to parse registry's information \
/// package.
///
/// The returned boolean is whether or not the summary has been yanked.
- fn parse_registry_package(&mut self, line: &str, config: &Config)
+ fn parse_registry_package(&mut self, line: &str)
-> CargoResult<(Summary, bool)> {
let RegistryPackage {
name, vers, cksum, deps, features, yanked
} = try!(json::decode::<RegistryPackage>(line));
let pkgid = try!(PackageId::new(&name, &vers, &self.source_id));
let deps: CargoResult<Vec<Dependency>> = deps.into_iter().map(|dep| {
- self.parse_registry_dependency(dep, config)
+ self.parse_registry_dependency(dep)
}).collect();
let deps = try!(deps);
let summary = try!(Summary::new(pkgid, deps, features));
}
/// Converts an encoded dependency in the registry to a cargo dependency
- fn parse_registry_dependency(&self, dep: RegistryDependency, config: &Config)
+ fn parse_registry_dependency(&self, dep: RegistryDependency)
-> CargoResult<Dependency> {
let RegistryDependency {
name, req, features, optional, default_features, target, kind
} = dep;
let dep = try!(DependencyInner::parse(&name, Some(&req),
- &self.source_id, config));
+ &self.source_id,
+ self.config));
let kind = match kind.as_ref().map(|s| &s[..]).unwrap_or("") {
"dev" => Kind::Development,
"build" => Kind::Build,
}
impl<'cfg> Registry for RegistryIndex<'cfg> {
- fn query(&mut self, dep: &Dependency, config: &Config) -> CargoResult<Vec<Summary>> {
+ fn query(&mut self, dep: &Dependency) -> CargoResult<Vec<Summary>> {
let mut summaries = {
- let summaries = try!(self.summaries(dep.name(), config));
+ let summaries = try!(self.summaries(dep.name()));
summaries.iter().filter(|&&(_, yanked)| {
dep.source_id().precise().is_some() || !yanked
}).map(|s| s.0.clone()).collect::<Vec<_>>()
_ => true,
}
});
- summaries.query(dep, config)
+ summaries.query(dep)
}
fn supports_checksums(&self) -> bool {
}
impl<'cfg> Registry for RegistrySource<'cfg> {
- fn query(&mut self, dep: &Dependency, config: &Config) -> CargoResult<Vec<Summary>> {
+ fn query(&mut self, dep: &Dependency) -> CargoResult<Vec<Summary>> {
// If this is a precise dependency, then it came from a lockfile and in
// theory the registry is known to contain this version. If, however, we
// come back with no summaries, then our registry may need to be
// updated, so we fall back to performing a lazy update.
if dep.source_id().precise().is_some() && !self.updated {
- if try!(self.index.query(dep, config)).is_empty() {
+ if try!(self.index.query(dep)).is_empty() {
try!(self.do_update());
}
}
- self.index.query(dep, config)
+ self.index.query(dep)
}
fn supports_checksums(&self) -> bool {
Ok(())
}
- fn download(&mut self, package: &PackageId, config: &Config) -> CargoResult<Package> {
- let hash = try!(self.index.hash(package, config));
+ fn download(&mut self, package: &PackageId) -> CargoResult<Package> {
+ let hash = try!(self.index.hash(package));
let path = try!(self.ops.download(package, &hash));
let path = try!(self.unpack_package(package, &path).chain_error(|| {
internal(format!("failed to unpack package `{}`", package))
}));
let mut src = PathSource::new(&path, &self.source_id, self.config);
try!(src.update());
- src.download(package, config)
+ src.download(package)
}
fn fingerprint(&self, pkg: &Package) -> CargoResult<String> {
use core::{Source, Registry, PackageId, Package, Dependency, Summary, SourceId};
-use util::{CargoResult, ChainError, human, Config};
+use util::{CargoResult, ChainError, human};
pub struct ReplacedSource<'cfg> {
to_replace: SourceId,
}
impl<'cfg> Registry for ReplacedSource<'cfg> {
- fn query(&mut self, dep: &Dependency, config: &Config) -> CargoResult<Vec<Summary>> {
+ fn query(&mut self, dep: &Dependency) -> CargoResult<Vec<Summary>> {
let dep = dep.clone().map_source(&self.to_replace, &self.replace_with);
- let ret = try!(self.inner.query(&dep, config).chain_error(|| {
+ let ret = try!(self.inner.query(&dep).chain_error(|| {
human(format!("failed to query replaced source `{}`",
self.to_replace))
}));
})
}
- fn download(&mut self, id: &PackageId, config: &Config) -> CargoResult<Package> {
+ fn download(&mut self, id: &PackageId) -> CargoResult<Package> {
let id = id.with_source_id(&self.replace_with);
- let pkg = try!(self.inner.download(&id, config).chain_error(|| {
+ let pkg = try!(self.inner.download(&id).chain_error(|| {
human(format!("failed to download replaced source `{}`",
self.to_replace))
}));
fn resolve<R: Registry>(pkg: PackageId, deps: Vec<Dependency>,
registry: &mut R)
-> CargoResult<Vec<PackageId>> {
- let config = Config::default().unwrap();
let summary = Summary::new(pkg.clone(), deps, HashMap::new()).unwrap();
let method = Method::Everything;
Ok(try!(resolver::resolve(&[(summary, method)],
&[],
- registry,
- &config)).iter().map(|p| {
+ registry)).iter().map(|p| {
p.clone()
}).collect())
}